# -*- coding: utf-8 -*-
# @Time    : 2019/11/18 0018 11:15
# @Author  : wulin
# @Email   :286075568@qq.com
# @FileName: mysql.py
# @Software: PyCharm

# 导入pymysql模块
import pymysql
from common.outlog import MyLog

# 导入pymysql模块
import pymysql
from common.outlog import MyLog

logger = MyLog('INFO')


# 连接database
class B2BMysql:
    def __init__(self):
        # 配置mysql参数
        self.mysql_info = {
            'mysqluser': "root",
            'mysqlpassword': "U7Hm&zJO3w1h4TwvwfIe",
            'mysqlport': 3306,
            'mysqlhost': 'mysql-test.frp.iwubida.com',
            'mysqldb': 'test_member',
            'mysqlcharset': "utf8"
        }

        # 初始化mysql配置

    def init_mysql(self):

        # 创建连接，执行语句的时候是在这个连接
        connect = pymysql.connect(
            user=self.mysql_info['mysqluser'],
            password=self.mysql_info['mysqlpassword'],
            port=self.mysql_info['mysqlport'],
            host=self.mysql_info['mysqlhost'],
            db=self.mysql_info['mysqldb'],
            charset=self.mysql_info['mysqlcharset']
        )

        # 获取游标
        cursor = connect.cursor()

        logger.info("正在恢复%test_member%数据库注册数据")
        # 一行一行执行SQL语句
        # 后台注册账户
        sql = "DELETE FROM auth_login WHERE login_name='1992335190@';"
        sql1 = "DELETE FROM member_user_info WHERE user_name='1992335190@';"
        sql2 = "DELETE FROM auth_login WHERE login_name='19923351899';"
        sql3 = "DELETE FROM member_user_info WHERE user_name='19923351899';"
        sql4 = "DELETE FROM auth_login WHERE login_name='19923351900';"
        sql5 = "DELETE FROM member_user_info WHERE user_name='19923351900';"
        sql6 = "DELETE FROM auth_login WHERE login_name='큐〓㊚1992335';"
        sql7 = "DELETE FROM member_user_info WHERE user_name='큐〓㊚1992335';"
        sql8 = "DELETE FROM auth_login WHERE login_name='18823351899';"
        sql9 = "DELETE FROM member_user_info WHERE user_name='18823351899';"


        try:
            # 执行SQL语句
            cursor.execute(sql)
            cursor.execute(sql1)
            cursor.execute(sql2)
            cursor.execute(sql3)
            cursor.execute(sql4)
            cursor.execute(sql5)
            cursor.execute(sql6)
            cursor.execute(sql7)
            cursor.execute(sql8)
            cursor.execute(sql9)
            logger.info("接口注册账户删除成功！")

            connect.commit()


        except:
            print
            "Error: unable to fecth data"

            # 关闭游标和连接
            cursor.close()
            connect.close()


# 调试代码
if __name__ == '__main__':
    mysql = B2BMysql()
    mysql.init_mysql()
